package com.qdlc.p2p.biz.processor.task.pay;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.processor.event.BorrowRepayUpRateValueEvent;
import com.qdlc.p2p.biz.processor.task.AbstractTaskProcessor;
import com.qdlc.p2p.biz.service.CollectPayService;
import com.qdlc.p2p.common.core.queue.TaskProcessorException;
import com.qdlc.p2p.common.core.queue.ValueEvent;
import com.qdlc.p2p.dal.dto.TppTradeLog;

/**
 * PS 加息代付
 *
 * @author wuaj
 */
@Service
public class BorrowRepayUpRatePayTaskProcessor extends AbstractTaskProcessor {

    @Resource
    @Qualifier("borrowRepayUpRatePayService")
    private CollectPayService borrowRepayUpRatePayService;

    @Override
    public boolean supports(ValueEvent event) {
        return event instanceof BorrowRepayUpRateValueEvent;
    }

    @Override
    public void process0(ValueEvent e) throws TaskProcessorException {
        BorrowRepayUpRateValueEvent event = (BorrowRepayUpRateValueEvent) e;
        List<TppTradeLog> tppTradeLogs = event.getTppTradeLogs(); // 交易Logs
        for (TppTradeLog tppTradeLog : tppTradeLogs) {
            // 代付请求
            borrowRepayUpRatePayService.requestOrder(tppTradeLog);
        }
    }
}
